package ua.diploma.hibernate.dto;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Класс секретный вопрос, мапится в бд
 * 
 * @author netstalk3r
 * 
 */
@Entity
@Table(name = "wc_secret_questions")
public class SecretQuestion {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Integer id;

	@Column(name = "question")
	private String question;

	@OneToMany(mappedBy = "secretQuesion", cascade = CascadeType.ALL)
	private Set<User> users;

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public SecretQuestion() {
		super();
	}

	public Integer getId() {
		return id;
	}

	public SecretQuestion(String question) {
		super();
		this.question = question;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	@Override
	public String toString() {
		return "SecretQuestion [id=" + id + ", question=" + question
				+ ", users=" + users + "]";
	}

	@Override
	public int hashCode() {
		int hash = 25;
		hash = hash * 9 + ((id == null) ? 0 : id.hashCode());
		hash = hash * 9 + ((question == null) ? 0 : question.hashCode());
		hash = hash * 9 + ((users == null) ? 0 : users.hashCode());
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof SecretQuestion))
			return false;
		SecretQuestion entry = (SecretQuestion) obj;
		return id.equals(entry.id) && question.equals(entry.question)
				&& users.equals(entry.users);
	}

}
